package com.rf.richfitwheel.advice;

import com.rf.richfitwheel.common.frm.http.HttpCode;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private int code = HttpCode.OK.value();
    private String msg;
    private T data;

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(HttpStatus.OK.value(), "success", data);
//        return new Result<T>(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
    }

    public static <T> Result<T> failure() {
        return failure(HttpStatus.BAD_REQUEST.value(), "failure");
//        return failure(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase());
    }

    public static <T> Result<T> failure(int errorCode, String errorMsg) {
        return failure(errorCode, errorMsg, null);
    }

    public static <T> Result<T> failure(int errorCode, String errorMsg, T data) {
        return new Result<T>(errorCode, errorMsg, data);
    }
}
